package org.vectrics.recruiter.job.event;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import org.vectrics.SystemException;
import org.vectrics.event.EventAttachment;
import org.vectrics.event.EventHandler;
import org.vectrics.hibernate.ThreadProperties;
import org.vectrics.recruiter.RecruitServiceLocator;
import org.vectrics.recruiter.job.Job;
import org.vectrics.recruiter.job.JobProvider;

public abstract class JobEventHandler extends EventHandler {

	public JobEventHandler() {
		super();
	}

	protected final Job getJob() {
		if (this.getEvent().getAttachments().size() == 0) {
			throw new SystemException("Could not find job attached to job event - event: " + this.getEvent().getDescription());
		}
		Iterator iter = this.getEvent().getAttachments().iterator();
		EventAttachment attachment = (EventAttachment)iter.next();
		Job job = RecruitServiceLocator.getJobProvider().findJob(new Long(attachment.getObjectId()));
		return(job);
	}

	protected Set findNotifyPersons() {
		Job job = this.getJob();
		Set notifyPersons = new HashSet();
		if (job.getPrimaryRecruiter() != null)
			notifyPersons.add(job.getPrimaryRecruiter());
		if (job.getSecondaryRecruiter() != null)
			notifyPersons.add(job.getSecondaryRecruiter());
		if (job.getHiringManager() != null)
			notifyPersons.add(job.getHiringManager());
		return(notifyPersons);
	}
}
